//
//  XLGUpdateSession+HTTPChannelProtocol.m
//  mcrmSAAS
//
//  Created by wjxfhxy on 15-4-10.
//  Copyright (c) 2015年 GuangZhouXuanWu. All rights reserved.
//

#import "XLGUpdateSessionChannelProtocol+HTTPChannelProtocol.h"

#import "XLGHTTPProtocolBase.h"

@interface UpdateSessionHTTPProtocol : XLGHTTPProtocolBase

@end

@implementation UpdateSessionHTTPProtocol

- (void)writeRequestProtocol:(writeRequestProtocolBlock)protocol
{
    NSString *token = [XLGContext context].m_token;
    NSString *URI = [NSString stringWithFormat:@"api/v5/Service/Get?token=%@", token];
    
    protocol(URI, XLGHTTPMethodTypeGet, NULL, nil,nil);
}

- (void)readResponseProtocol:(NSDictionary *)jsonDictionary output:(NSObject **)obj
{
    if(jsonDictionary != nil)
    {
        BOOL result = NO;
        BOOL code = [jsonDictionary[@"Code"] boolValue];
        BOOL success = [jsonDictionary[@"Success"] boolValue];
        
        if(code && success)
            result = YES;
        
        //session 过期
        if(result == NO)
            _nErrorcode = -25013;
        
        *obj = [NSNumber numberWithBool:result]; 
    }
}

@end

@implementation XLGUpdateSessionChannelProtocol (HTTPChannelProtocol)

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"

- (CProtocolBase*)updateSessionProtocol
{
    return [UpdateSessionHTTPProtocol new];
}

#pragma clang diagnostic pop

@end
